import 'package:flutter/material.dart';

class TitleBar extends StatelessWidget {
  final BuildContext context;
  final String title;
  final bool isLight;
  final String? right;
  final GestureTapCallback? ontap;
  const TitleBar(this.context, this.title, this.isLight,
      {Key? key, this.right, this.ontap})
      : super(key: key);
  static getRight(String? right, GestureTapCallback? ontap, bool isLight) {
    if (right == null) {
      return Container();
    } else {
      return InkWell(
        onTap: ontap,
        child: Padding(
          padding: const EdgeInsets.all(10),
          child: Text(
            right,
            style: TextStyle(color: isLight ? Colors.white : Colors.black),
          ),
        ),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 10),
      child: Stack(
        children: [
          Padding(
            padding: const EdgeInsets.only(top: 10, bottom: 10),
            child: Center(
              child: Text(
                title,
                style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: isLight ? Colors.white : Colors.black),
              ),
            ),
          ),
          Row(
            children: [
              InkWell(
                onTap: () {
                  Navigator.pop(context);
                },
                child: Padding(
                  padding: const EdgeInsets.all(10),
                  child: Icon(
                    Icons.arrow_back_ios_new_outlined,
                    color: isLight ? Colors.white : Colors.black,
                  ),
                ),
              ),
              getRight(right, ontap, isLight),
            ],
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
          ),
        ],
      ),
    );
  }
}
